<template>
	<view class="real-name">
		<block v-if="realInfo">
			<view class="empty-box" v-if="realInfo.status.value == 'review'">
				<image class="image" src="@/static/settlement-empty.png" mode="aspectFill"></image>
				<view class="text">审核中</view>
			</view>
			<view class="empty-box" v-else-if="realInfo.status.value == 'reject'">
				<u-icon name="info-circle-fill" color="#9e2024" size="204rpx"></u-icon>
				<view class="text">审核失败</view>
				<button class="btn" @click="goReal">重新开户</button>
			</view>
			<view class="open-info">
				<image class="bg" src="@/static/income.png" mode="widthFix"></image>
				<view class="content">
					<view class="info">
						<view class="name-box">
							<text class="name">{{ realInfo.real_name }}</text>
							<view class="authentication">已认证</view>
						</view>
						<view class="idcard-box">
							<view class="idcard">{{ idcardEncrypt(realInfo.id_card) }}</view>
						</view>
					</view>
				</view>
			</view>
		</block>
		<view class="empty-box" v-else>
			<image class="image" src="@/static/settlement-empty.png" mode="aspectFill"></image>
			<view class="text">您暂未开户</view>
			<button class="btn" @click="goReal">去开户</button>
		</view>
	</view>
</template>

<script>
	import { getRealInfo } from '@/api/api'

	export default {
		data () {
			return {
				realInfo: {},
			}
		},
		onShow () {
			getRealInfo().then(res => {
				if (res) {
					this.realInfo = res.data
				}
			})
		},
		methods: {
			goReal () {
				uni.navigateTo({
					url: '/pages/my/realName/realInfo'
				})
			}
		},
		computed: {
			idcardEncrypt () {
				return (idcard) => {
					if (idcard) {
						let str = idcard + ''
						let lenght = str.length
						
						let a = str.slice(0, 6)
						let b = str.slice(lenght - 4, lenght - 1)
						
						return `${a}********${b}`
					}
					
					return ''
				}
			}
		},
	}
</script>

<style lang="scss">
.real-name {
	box-sizing: border-box;
	min-height: 100%;
	background-color: #f5f5f5;
	.open-info {
		height: 208rpx;
		overflow: hidden;
		position: relative;
		.bg {
			position: absolute;
			top: 0;
			left: 0;
			z-index: 0;
			width: 750rpx;
		}
		.content {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			z-index: 5;
			padding-left: 62rpx;
			display: flex;
			align-items: center;
			.info {
				flex: 1;
				.name-box {
					display: flex;
					align-items: center;
					.name {
						color: #fff;
						font-size: 36rpx;
						font-weight: bold;
					}
					.authentication {
						margin-left: 12rpx;
						margin-right: 8rpx;
						width: 100rpx;
						height: 38rpx;
						border-radius: 38rpx;
						color: #fff;
						font-size: 22rpx;
						text-align: center;
						line-height: 38rpx;
						background-color: #5749f7;
					}
				}
				.idcard-box {
					margin-top: 18rpx;
					display: flex;
					align-items: center;
					.text {
						margin-left: 10rpx;
						color: #fff;
						font-size: 26rpx;
					}
					.idcard {
						color: #fff;
						font-size: 26rpx;
					}
				}
			}
			.edit {
				width: 178rpx;
				color: #fff;
				font-size: 28rpx;
				text-align: center;
			}
		}
	}
	.empty-box {
		padding: 150rpx 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		.image {
			width: 204rpx;
			height: 204rpx;
		}
		.text {
			margin-top: 14rpx;
			color: #333;
			font-size: 34rpx;
			font-weight: bold;
		}
		.btn {
			margin: 108rpx auto 0;
			border-radius: 100rpx;
			width: 440rpx;
			height: 100rpx;
			color: #fff;
			font-size: 36rpx;
			font-weight: bold;
			line-height: 100rpx;
			background-color: #5749f7;
		}
	}
}
</style>
